package com.meishij.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.meishij.R;
import com.meishij.entry.MallSellEntry;

import java.util.List;

/**
 * Created by 肖荣 on 2016/10/15.
 */

public class MallItemConsultRecyclerAdapter extends RecyclerView.Adapter<MallItemConsultRecyclerAdapter.ViewHolder> {
    private Context context;
    private List<MallSellEntry.ObjBean.QaListBean> list;


    public MallItemConsultRecyclerAdapter(Context context, List<MallSellEntry.ObjBean.QaListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_mall_sell_consult_recycler_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.consult_item_icon.setImageURI(list.get(position).getUser_info().getAvatar());
        holder.consult_time.setText(list.get(position).getTime());
        holder.consult_user_name.setText(list.get(position).getUser_info().getUser_name());
        holder.consult_q_icon.setImageURI(list.get(position).getQ_icon());
        holder.consult_q_text.setText(list.get(position).getQ());
        holder.consult_a_icon.setImageURI(list.get(position).getA_icon());
        holder.consult_a_text.setText("商城客服:"+list.get(position).getA());
        holder.consult_a_text.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private SimpleDraweeView consult_item_icon;
        private TextView consult_user_name;
        private TextView consult_time;
        private SimpleDraweeView consult_q_icon;
        private TextView consult_q_text;
        private SimpleDraweeView consult_a_icon;
        private TextView consult_a_text;

        public ViewHolder(View itemView) {
            super(itemView);
            consult_item_icon = ((SimpleDraweeView) itemView.findViewById(R.id.consult_item_icon));
            consult_user_name = ((TextView) itemView.findViewById(R.id.consult_user_name));
            consult_time = ((TextView) itemView.findViewById(R.id.consult_time));
            consult_q_icon = ((SimpleDraweeView) itemView.findViewById(R.id.consult_q_icon));
            consult_q_text = ((TextView) itemView.findViewById(R.id.consult_q_text));
            consult_a_icon = ((SimpleDraweeView) itemView.findViewById(R.id.consult_a_icon));
            consult_a_text = ((TextView) itemView.findViewById(R.id.consult_a_text));
        }
    }
}
